<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Bab_model extends CI_Model {
	
	public function __construct()
	{
		parent::__construct();
	}
	
	function get($id = null) 
	{
		$this->db->select()->from('project_bab');
		if ($id != null) 
		{
			$this->db->where('id', $id);
		}
		else 
		{
			$this->db->order_by('id');
		}
 
		$query = $this->db->get();
 
		if ($id != null) 
		{
			return $query->row_array();
		}
		else 
		{
			return $query->result_array();
		}
	}
	
	public function is_bab_exist($id)
	{
		$query = $this->db->get_where('project_bab', array('id' => $id));
		if($query->num_rows() > 0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	public function update($id,$data)
	{
		$this->db->where('id', $id);
		$this->db->update('project_bab', $data); 
	}
	
	public function insert($data)
	{
		if($this->db->insert('project_bab', $data))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	public function delete($id)
	{
		$this->db->delete('project_bab', array('id' => $id) ); 
	}
}